package com.huiying.mapper;

import com.huiying.entity.entity.Favorite;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: lsh
 * @Date: 2024/11/24/16:51
 * @Description: 用户点赞数据访问类
 */
@Mapper
public interface FavoriteMapper {
    @Insert("insert into userfavorites(user_id, content_id, favorite_type, create_time)" +
            "values (#{userId},#{contentId},#{favoriteType},#{createTime})")
    void insert(Favorite favorite);

    @Delete("delete from userfavorites where content_id = #{demandId} and user_id = #{userId} and favorite_type = #{contentType}")
    void delete(@Param("demandId") Long demandId,
                @Param("userId") Long userId,
                @Param("contentType") String contentType);

    @Select("select count(*) from userfavorites where content_id = #{demandId} and favorite_type = #{contentType}")
    Long getFavoriteCountByDemandId(@Param("demandId") Long demandId,
                                    @Param("contentType") String contentType);

    @Delete("delete from userfavorites where content_id =#{demandId} and favorite_type = #{demand}")
    void deleteByContentId(@Param("demandId") Long demandId,
                           @Param("demand") String demand);

    @Select("select id, user_id, content_id, favorite_type, create_time " +
            "from userfavorites where content_id = #{contentId} and user_id = #{userId} and favorite_type = #{contentType}")
    Favorite getByContentIdAndUserId(@Param("contentId") Long contentId,
                                     @Param("userId") Long userId,
                                     @Param("contentType") String contentType);

    @Select("select content_id from userfavorites where user_id = #{userId} and favorite_type = #{contentType}")
    List<Long> getContentId(@Param("userId") Long userId,
                            @Param("contentType") String contentType);
}
